//
//  XMWithdrawDetailView.m
//  XMJJ_zml
//
//  Created by apple on 2025/5/16.
//

#import "XMWithdrawDetailView.h"
#import "XMWithdrawDetailCell.h"

@interface XMWithdrawDetailView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tbl;

@property (nonatomic, strong) NSMutableArray *withdrawDetailModelArr;

@end

@implementation XMWithdrawDetailView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.navView];
    self.navTitleLabel.text = @"提现明细";
    
    [self addSubview:self.tbl];
}

- (void)setContentWithWithdrawDetailModelArr:(NSArray *)withdrawModelArr
                                        page:(NSInteger)page {
    if (page == 1) {
        [self.withdrawDetailModelArr removeAllObjects];
    }
    if (withdrawModelArr.count < 10) {
        [_tbl.mj_footer endRefreshingWithNoMoreData];
    }
    else {
        [_tbl.mj_footer endRefreshing];
    }
    [self.withdrawDetailModelArr addObjectsFromArray:withdrawModelArr];
    [_tbl reloadData];
}

#pragma mark - Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.withdrawDetailModelArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return KScaleWidth(129.0);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    XMWithdrawDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XMWithdrawDetailCellName" forIndexPath:indexPath];
    [cell setContentWithRecordModel:self.withdrawDetailModelArr[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - Init
- (UITableView *)tbl {
    if (!_tbl) {
        _tbl = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavagationBarH, self.width, self.height - kNavagationBarH)];
        _tbl.delegate = self;
        _tbl.dataSource = self;
        _tbl.backgroundColor = kColorHEX(0xf7f7f7);
        _tbl.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tbl registerClass:[XMWithdrawDetailCell class] forCellReuseIdentifier:@"XMWithdrawDetailCellName"];
        if (@available(iOS 15.0, *)) {
            _tbl.sectionHeaderTopPadding = 0;
        } else {
            _tbl.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            // Fallback on earlier versions
        }
        XMWeakSelf;
        _tbl.mj_header = [MJRefreshStateHeader headerWithRefreshingBlock:^{
            if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(refreshData)]) {
                [weakSelf.delegate refreshData];
            }
        }];
        _tbl.mj_footer = [MJRefreshAutoStateFooter footerWithRefreshingBlock:^{
            if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(loadMore)]) {
                [weakSelf.delegate loadMore];
            }
        }];
    }
    return _tbl;
}

- (NSMutableArray *)withdrawDetailModelArr {
    if (!_withdrawDetailModelArr) {
        _withdrawDetailModelArr = [NSMutableArray array];
    }
    return _withdrawDetailModelArr;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
